// pages/mes/compony-auth/compony-auth.js
const app = getApp();
const _scaleArr = ['0-50' , '50-100' , '100-500' , '500-1000' , '1000-5000' , '5000-10000' , '10000以上'];
const _financeArr = ['未融资' , '天使轮' , 'A轮' , 'B轮' , 'C轮' , '已上市'];
import Toast from '../../../component/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        componyName:'',
        businessLicense:'',
        industry:'',
        scale:'',
        financingStage:'',
        scaleArr:[],
        financeArr: [],
        industrys:[]
    },
    /**
     * -------------------网络请求部分-------------------
     */
    getEnterpriseInfoById(){
        wx.showLoading({
            title: '正在查询...',
            mask: true
        });
        wx.request({
            url: app.globalData.serverAddress.getEnterpriseInfoById,
            data: {
                userInfoId: app.userInfo.Id
            },
            header: {
                'Authorization': "Bearer " + app.globalData.token
            },
            method: 'GET',
            success: function(res) {
                console.log('getEnterpriseInfoById success' , res);
                if (res.statusCode == 200 && res.data.CodeStatus == 20000) {

                }
            },
            fail: function (res) { console.log("getEnterpriseInfoById fail" , res)},
            complete: function(res) {wx.hideLoading();},
        })
    },
    getEnterpriseParams() {
        let that = this;
        wx.showLoading({
            title: '加载中...',
            mask: true
        });
        wx.request({
            url: app.globalData.serverAddress.getEnterpriseParams,
            header: {
                'Authorization': "Bearer " + app.globalData.token
            },
            method: 'GET',
            success: function (res) {
                console.log("getEnterpriseParams success:", res);
                if (res.statusCode == 200 && res.data.CodeStatus == 20000) {
                    that.setData({
                        financeArr: res.data.BodyContent.FinancingStage,
                        scaleArr: res.data.BodyContent.Scale,
                        industrys: res.data.BodyContent.Industrys
                    })
                }
            },
            fail: function (res) { console.log("getEnterpriseParams fail", res); },
            complete: function (res) { wx.hideLoading(); },
        })
    },
    /**
     * -------------------网络请求部分-------------------
     */

    /**
     * ===================事件处理部分===================
     */
    clickStep(){
        if (!this.data.componyName){
            Toast("请输入公司名称！");
            return;
        }
        if (!this.data.businessLicense) {
            Toast("请上传营业执照！");
            return;
        }
        if (!this.data.industry) {
            Toast("请选择所属行业！");
            return;
        }
        if (!this.data.scale) {
            Toast("请选择人员规模！");
            return;
        }
        if (!this.data.financingStage) {
            Toast("请选择融资阶段！");
            return;
        }
        let obj = {
            componyName: this.data.componyName,
            businessLicense: this.data.businessLicense,
            industry: this.data.industry,
            scale: this.data.scale,
            financingStage: this.data.financingStage
        };
        app.globalData.enterpriseInfo = obj;
        wx.navigateTo({
            url: '/pages/compony-pages/commit-compony-auth/commit-compony-auth'
        })
    },
    scalePickerChange(e){
        let scale = this.data.scaleArr[e.detail.value]
        this.setData({
            scale: scale
        });
    },
    financingPickerChange(e){
        let financingStage = this.data.financeArr[e.detail.value];
        this.setData({
            financingStage: financingStage
        });
    },
    onClick(e){
        let index = e.currentTarget.dataset.index;
        let url = '';
        switch(index){
            case '1':
                url = "/pages/compony-pages/compony-name/compony-name?componyName=" + this.data.componyName
                break;
            case '2':
                url = "/pages/compony-pages/compony-id/compony-id"
                break;
            case '3':
                let obj = JSON.stringify(this.data.industrys);
                url = "/pages/compony-pages/compony-trade/compony-trade?parmas=" + obj
                break;
        }
        wx.navigateTo({
            url: url
        })
    },
    /**
     * ===================事件处理部分===================
     */


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getEnterpriseInfoById();
        this.getEnterpriseParams();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})